package com.amumu.drama.common.config.redis;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by freethinker on 2021-05-31.
 */
public interface IConfig {

    default List<Long> readAsLongList(String content, String separatorChars) {
        if (StringUtils.isBlank(content)) {
            return new ArrayList<>();
        }

        String[] lines = StringUtils.split(content, separatorChars);
        if (lines == null || lines.length == 0) {
            return new ArrayList<>();
        }

        List<Long> list = new ArrayList<>();
        for (String line : lines) {
            String s = line.trim();
            if (s.length() == 0) {
                continue;
            }
            list.add(Long.parseLong(s));
        }
        return list;
    }

    default List<String> readAsStringList(String content, String separatorChars) {
        if (StringUtils.isBlank(content)) {
            return new ArrayList<>();
        }

        String[] lines = StringUtils.split(content, separatorChars);
        if (lines == null || lines.length == 0) {
            return new ArrayList<>();
        }

        List<String> list = new ArrayList<>();
        for (String line : lines) {
            String s = line.trim();
            if (s.length() == 0) {
                continue;
            }
            list.add(s);
        }
        return list;
    }

    default List<Integer> readAsIntegerList(String content, String separatorChars) {
        if (StringUtils.isBlank(content)) {
            return new ArrayList<>();
        }

        String[] lines = StringUtils.split(content, separatorChars);
        if (lines == null || lines.length == 0) {
            return new ArrayList<>();
        }

        List<Integer> list = new ArrayList<>();
        for (String line : lines) {
            String s = line.trim();
            if (s.length() == 0) {
                continue;
            }
            list.add(Integer.valueOf(s));
        }
        return list;
    }
}
